from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.api import urlfetch

from PyRSS2Gen import RSS2
from datetime import datetime
from base64 import b64decode

class FeedHandler(webapp.RequestHandler):
	def get(self):
		"""
		Answers the GET method. Generates an RSS feed from stored Google Wave
		updates.
		"""
		# Manage authentication / authorisation
		user = users.get_current_user()
		
		# Get user settings from data store
		# Get relevant updates from data store
		# Serialise into RSS / ATOM feed
		if user:
			self.atomFeed = RSS2(title = 'Wave Stream of %s' % user.nickname(),
								 link = 'http://wave-stream.appspot.com/settings',
								 description = 'Simple RSS Feed for you Google Wave.',
								 lastBuildDate = datetime.now())
			self.response.out.write(self.atomFeed.to_xml(encoding = 'UTF-8'))
		else:
			self.response.out.write('No User')